<?php
if (isset($_GET['idc']))
    $cid = $_GET['idc'];
else
    $cid = 1;

if (isset($_GET['parent_dir']))
    $parent_dir = $_GET['parent_dir'];
else
    $parent_dir = 1;

$backDir = $parent_dir;
?>

<div id="commandbar">
    <div id="menubar">
        <ul>
            <li><a href="createcategory.php?idc=<?php echo $cid; ?>" title="Add category">
                    <img src="<?php echo Yii::app()->theme->baseUrl ?>/images/new_folder.png"/></a></li>
            <li><a href="createfile.php?idc=<?php echo $cid; ?>" title="Add file">
                    <img src="<?php echo Yii::app()->theme->baseUrl ?>/images/new_doc.png"/></a></li>
            <li><a href="createlink.php?idc=<?php echo $cid; ?>" title="Add link">
                    <img src="<?php echo Yii::app()->theme->baseUrl ?>/images/new_link.png"/></a></li>
        </ul>
    </div>
    <div id="topbar">
        <a href="../protected/ActionDispatcher.php?action=logout">Esci</a>
    </div>
    <hr/>
</div>
<div class="contents">

    <?php

    $parent_dir = $cid;
    if (count($categories) == 0) {
        echo 'showcategory.category.empty';
    } else {
        ?>

        <div class="contents-table">                    
            <div class="contents-table-header">
                <div class="contents-table-caption-col0">&nbsp;</div>
                <div class="contents-table-caption-col1">Titolo</div>
                <div class="contents-table-caption-col2">Dimensione</div>
                <div class="contents-table-caption-col3">Ultima modifica</div>
            </div>
            <hr/>

            <?php if ($cid != 1) { ?>
                <div class="contents-table-row">
                    <div class="contents-table-col">..</div>
                    <div class="contents-table-col">
                        <a href='showcategory.php?idc=<?php echo $backDir ?>'>
                            Parent directory</a>
                    </div>
                    <div class="contents-table-col">&nbsp;</div>
                    <div class="contents-table-col">&nbsp;</div>
                </div>
                <hr/>
            <?php } ?>

            <?php
            // Categories
            foreach($categories as $category) {
                ?>
                <div class="contents-table-row" id="category-id-<?php echo $category->cid ?>">
                    <div class="contents-table-col"><img src='../images/directory.png'> </div>
                    <div class="contents-table-col">
                        <a href='showcategory.php?idc=<?php echo $category->cid ?>&parent_dir=<?php echo $category->parent_dir ?>'><?php echo $category->name ?></a>
                        <span class="actions" id="actions-category-id-<?php echo $category->cid ?>">
                            [<a href=deleteelement.php?idc=<?php echo $category->cid ?>&parent_dir=<?php echo $category->parent_dir ?>>Elimina</a>
                            | 
                            <a href=modifycategory.php?idc=<?php echo $category->cid ?>&parent_dir=<?php echo $category->parent_dir ?>>Modifica</a>]
                        </span>
                    </div>
                    <div class="contents-table-col">&nbsp;</div>
                    <div class="contents-table-col">&nbsp;</div>
                </div>
                <hr/>
                <?php
            }
        }
        ?>
    </div>
</div>
